﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace WebApi.Domain
{
    public class Dbinit
    {
        public static void Init() 
        {
            using (var db = new AdminDB()) 
            {
                var dbExist = db.Database.EnsureCreated();

                var tempBrand = db.Brands.Any();

                if (!tempBrand)
                {
                    var brand = new Brand
                    {
                        BrandName = "小米",
                        Say = "性价比高"
                    };
                    db.Brands.Add(brand);
                    db.SaveChanges();
                    db.Produces.AddRange(new Produce[]
                    {
                    new Produce
                    {
                        proName="黑鲨游戏手机",
                        FullDecs="实体按键手机",
                        BrandId=brand.Id

                    },

                    new Produce
                    {
                        proName="小米10手机",
                        FullDecs="首个旗舰手机",
                        BrandId=brand.Id

                    }


                    });

                    db.SaveChanges();

                }



            }   
        }
    }
}
